import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    name: '大脸红',
    num:6,
    age:"18",
    hobby:"睡觉",
    childnum:[
      {id:1,fruits:"西瓜",price:5},
      {id:2,fruits:"香蕉",price:3.5},
      {id:3,fruits:"苹果",price:4},
      {id:4,fruits:"桃子",price:6},
      {id:5,fruits:"草莓",price:10},
      {id:6,fruits:"樱桃",price:20},
      {id:7,fruits:"葡萄",price:8},
  ]
  },
  mutations: {
    // SET_NAME(state, val) {
    //   state.name = val
    // },
   addnum(state,val){
     state.num = state.num +val
   }
  },
  actions: {
    adds({commit},val){
      setTimeout(function(){
        commit('addnum',val)
      },3000)
    }
    // deletes({commit},val){
    //   setTimeout(() => {
    //     commit('delete',val)
    //   }, 2000);
    // },
    // A({dispatch}, val) {
    //   setTimeout(() => {
    //     console.log('trigger')
    //     dispatch('SET_TEST', val)
    //   }, 2000);
    // },
    // SET_TEST({commit}, val) {
    //   setTimeout(() => {
      
    //     commit('SET_NAME', val)
    //   }, 3000);
    // }
  },
  modules: {
    list: {
      namespaced: true,
      state: {
        name: 'list'
      }
    }
  }
})
